﻿#include "practice.h"


int main(int argc, char **argv)
{
    OSGQT_INIT_CODE

    QObject::connect(&widget, &osgQOpenGLWidget::initialized,   [  &arguments,
                                                                   &widget ]
    {
        // 设置相机
        {
            osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
            keyswitchManipulator->addMatrixManipulator('1', "Trackball", new osgGA::TrackballManipulator());
            keyswitchManipulator->addMatrixManipulator('2', "Flight", new osgGA::FlightManipulator());
            keyswitchManipulator->addMatrixManipulator('3', "Drive", new osgGA::DriveManipulator());
            keyswitchManipulator->addMatrixManipulator('4', "Terrain", new osgGA::TerrainManipulator());
            keyswitchManipulator->addMatrixManipulator('5', "Orbit", new osgGA::OrbitManipulator());
            keyswitchManipulator->addMatrixManipulator('6', "FirstPerson", new osgGA::FirstPersonManipulator());
            keyswitchManipulator->addMatrixManipulator('7', "Spherical", new osgGA::SphericalManipulator());
            widget.getOsgViewer()->setCameraManipulator(keyswitchManipulator.get());

            // add the state manipulator
        widget.getOsgViewer()->addEventHandler(new osgGA::StateSetManipulator(widget.getOsgViewer()->getCamera()->getOrCreateStateSet()));

        // add the thread model handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::ThreadingHandler);

        // add the window size toggle handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::WindowSizeHandler);

        // add the stats handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::StatsHandler);

        // add the help handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));

        // add the record camera path handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::RecordCameraPathHandler);

        // add the LOD Scale handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::LODScaleHandler);

        // add the screen capture handler
        widget.getOsgViewer()->addEventHandler(new osgViewer::ScreenCaptureHandler);

        // load the data
        // std::vector<std::string> files = {"cow.osg"};
        // osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(files);

        // if(!loadedModel)
        // {
        //     std::cout << arguments.getApplicationName() << ": No data loaded" << std::endl;
        //     return 1;
        // }
        // osgUtil::Optimizer optimizer;
        // optimizer.optimize(loadedModel);
        Practice p;
        widget.getOsgViewer()->setSceneData(p.createQuad().get());

        }
    });

    widget.show();

    return app.exec();
}